package com.gitee.zhuhjay.xunfei.sdk.model;

import com.gitee.zhuhjay.xunfei.sdk.consts.ApiVersion;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author ZhuHJay
 * @since 2023/11/13 20:14
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ModelParams {

    /**
     * 采样率：决定结果随机性[0,1]; default=0.5
     */
    private Float temperature = 0.5f;
    /**
     * 模型回答的最大长度; v1.5:[1,4096]; v2.0:[1,8192]; default=2048
     */
    private Integer maxTokens = 2048;
    /**
     * 从k个候选中随机选择一个:[1,6]; default=4
     */
    private Integer topP = 4;

    /**
     * 参数校验
     *
     * @param apiVersion api版本
     */
    public void check(ApiVersion apiVersion) {
        if (temperature < 0 || temperature > 1) {
            throw new IllegalArgumentException("temperature must be in [0, 1]");
        }
        if (ApiVersion.V1_5 == apiVersion) {
            if (maxTokens < 1 || maxTokens > 4096) {
                throw new IllegalArgumentException("maxTokens must be in [1, 4096]");
            }
        } else if (ApiVersion.V2_0 == apiVersion) {
            if (maxTokens < 1 || maxTokens > 8192) {
                throw new IllegalArgumentException("maxTokens must be in [1, 8192]");
            }
        } else {
            throw new IllegalArgumentException("apiVersion must be in [V1_5, V2_0]");
        }
        if (topP < 1 || topP > 6) {
            throw new IllegalArgumentException("topP must be in [1, 6]");
        }
    }

}
